/**
 *    Copyright 2009-2020 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.apache.ibatis.aapl.country;

import org.apache.ibatis.aapl.annotation.*;
import org.apache.ibatis.aapl.annotation.impl.CityAreaTestInjectionStrategy;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author gu
 * @date 2020/3/9 12:00
 */
@Mapper
@TableWatcher(value = "city")
public interface CityMapper {
  /**
   * 获取前10个城市的具体信息
   *
   * @param offset 偏移量
   * @param limit  限制
   * @return 城市列表
   */
  @EnhanceAfterQuery(strategies = {CityAfterStrategy.class})
  List<City> selectCities(@Param("offset") int offset, @Param("limit") int limit);

  @Select("select id from city limit 5")
  List<City> selectId();

  /**
   * 插入一个城市
   *
   * @param city 要插入的城市
   * @return 插入成功的条数
   */
  @StormId
  @FieldInjection(props = {"countryCode"}, strategies = {CityAreaTestInjectionStrategy.class})
  int insert(City city);

  /**
   * 当1等于2的时候
   * 删除所有的城市记录
   *
   * @return 实际删除条数
   */
  int deleteCities();

  /**
   * 查询总数量
   *
   * @return 数量
   */
  @Select("select count(*) from city")
  int selectCount();

  @Select("select()")
  List<Country> select();

  @Select("selectOne()")
  City selectOne(int id);

}
